/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package data;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;
/**
 *
 * @author NS
 */
public class List_User {
    private Connection connect;
    public List_User(Connection connect){
        this.connect = connect;
    }
    public ArrayList<UserInfo> queryUserList(String username){
            Statement select;
            UserInfo user = null;
            ArrayList<UserInfo> userList = null;
            try {
                    select = connect.createStatement();
                    String table = "USERTBL";
                    String cond = "";
                    if(!username.equals("ADMIN")) cond = " WHERE USERNAME = '" + username + "'";
                    System.out.println("SELECT * FROM " + table + cond);
                    ResultSet rs = select.executeQuery("SELECT * FROM " + table + cond);
                    userList = new ArrayList<UserInfo>();
                    
                    while(rs.next()){
                        user = new UserInfo();
                        user.setID(rs.getInt(1));
                        user.setUsername(rs.getString(2));
                        user.setPwd(rs.getString(3));
                        user.setDefTbspace(rs.getString(4));
                        user.setTmpTbspace(rs.getString(5));
                        user.setAccStatus(rs.getString(6));
                        user.setQuota(rs.getString(7));
                        user.setProfile(rs.getString(8));
                        user.setRole(rs.getString(9));
                        //System.out.println(rs.getString(2) + " " + rs.getString(9));
                        userList.add(user);
                    }
//                    for(int i = 0; i < userList.size(); i++){
//                        System.out.println(userList.get(i).getID());
//                        System.out.println(userList.get(i).getUsername());
//                        System.out.println(userList.get(i).getFullname());
//                        System.out.println(userList.get(i).getAddr());
//                        
//                    }
            } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
            }
            return userList;
	}
    
}
